/*************************************************************************
 * AUTHOR		 : Chris Hayes
 * STUDENT ID	 : 656960
 * ASSIGNMENT #5 : Multi-Dimensional Array - Tic Tac Toe
 * CLASS		 : CS1B
 * SECTION		 : MW12:30
 * DUE DATE		 : June 15, 2011
 *************************************************************************/

#include "tictacheader.h"

/**************************************************************************
* FUNCTION ScoreBoard
*__________________________________________________________________________
* This function outputs a properly formatted score board.  It begins by
* clearing the screen and outputs the player names and their scores as
* as well as the number of ties.
*__________________________________________________________________________
* PRE-CONDITIONS
*  player1 : The name of player1 should be previously defined  - Value
*  player2 : The name of player2 should be previously defined  - Value
*  score1  : The score of player1 should be previously defined - Value
*  score2  : The score of player2 should be previously defined - Value
*  ties	   : The number of ties should be previously defined   - Value
*
* POST-CONDITIONS
*   There are no post-conditions for this function.
**************************************************************************/

void ScoreBoard(string player1, int score1, string player2,
				int score2, int ties)
{
	//VARIABLES
	int size;			 //Size of the box					- CALC
	int player1length1;	 //used for setw before player1		- CALC
	int player1length2;	 //used for setw after player1
	int player2length1;	 //used for setw before player2		- CALC
	int player2length2;  //used for setw after player2 	- CALC

	//CALCULATE size of spacing for names and score
	player1length1 = (player1.length() % 2 == 1
						? player1.length()/2 + 1
						: player1.length()/2);

	player1length2 = player1.length()/2 + 1;

	player2length1 = (player2.length() % 2 == 1
						? player2.length()/2 + 1
						: player2.length()/2);

	player2length2 = player2.length()/2 + 1;

	size = player1.length() + player2.length() + 31;

	cout << left;

	//OUTPUT - top line
	for(int i = 0; i < size; i++)
	{
		cout << '-';
	}

	//OUTPUT - Names and tie game
	cout << endl;
	cout << "|   " << setw(player1.length() + 3) << player1;
	cout << setw(4) << '|' << setw(12) <<"Tie Games" << setw(4) <<'|';
	cout << setw(player2.length() + 3) << player2 << "|";
	cout << endl;

	//OUTPUT - Divider line
	for(int i = 0; i < size; i++)
	{
		cout << '-';
	}

	//OUTPUT - player 1 score
	cout << endl;
	cout << setw(4) << '|' << setw(player1length1 - 1) << ' ';
	cout << setw(player1length2) << score1 << setw(3) << ' ';

	//OUTPUT - ties
	cout << setw(8) << '|' << setw(8) << ties;

	//OUTPUT - player 2 score
	cout << setw(4) << '|';
	cout << setw(player2length1 - 1) << ' ';
	cout << setw(player2length2) << score2  << setw(3) << ' ' << '|';
	cout << endl;

	//OUTPUT - bottom line
	for(int i = 0; i < size; i++)
	{
		cout << '-';
	}

	cout << endl << endl;
	cout << right;
}
